package jvm;

import java.util.concurrent.CountDownLatch;

/**
 * 减法计数器
 *
 * @author Europa
 * @create 2020-05-29 22:57
 */
public class CountDownLatchDemo {

    public static void main(String[] args) {
        int num = 6;
        CountDownLatch countDownLatch = new CountDownLatch(num);

        for (int i = 0; i < num; i++) {
            Thread thread = new Thread(() -> {
                System.out.println("进来 "+Thread.currentThread().getName());
                //num - 1
                countDownLatch.countDown();
            });
            thread.start();
        }
        try {
            //计数器归零,在向下执行
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("结束");
    }
}
